package com.tfleo.mealssenger.balloon;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import com.google.android.maps.MapView;
import com.tfleo.mealssenger.PlaceActivity;
import com.tfleo.mealssenger.object.Place;


public class UsersOverlay extends BalloonItemizedOverlay<CustomOverlayItem> {
	private ArrayList<CustomOverlayItem> mOverlays = new ArrayList<CustomOverlayItem>();
	private Context mContext;
	
	public UsersOverlay(Drawable defaultMarker, MapView mapView) {
		super(boundCenterBottom(defaultMarker), mapView);
		mContext = mapView.getContext();
	}

	@Override
	protected CustomOverlayItem createItem(int i) {
		return mOverlays.get(i);
	}

	@Override
	public int size() {
		return mOverlays.size();
	}
	
	@Override
	protected boolean onBalloonTap(int index, CustomOverlayItem item) {
		//TODO: intent details
//		Intent i = new Intent(mContext, PlaceActivity.class); 
//		Place p;
//		if((p = mOverlays.get(index).getPlace()) != null) {
//			i.putExtra("id", p.id);
//			i.putExtra("name", p.name);
//			i.putExtra("address", p.address);
//			i.putExtra("description", p.description);
//			i.putExtra("category", p.category);
//		} else {
//	        i.putExtra("id", mOverlays.get(index).getId());
//	        i.putExtra("name", mOverlays.get(index).getTitle());
//		}
//        mContext.startActivity(i); 
		return true;
	}
	
	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow) { 		
		super.draw(canvas, mapView, false);

	}
	
	public void addOverlay(CustomOverlayItem overlay) {
	    mOverlays.add(overlay);
	    populate();
	    setLastFocusedIndex(-1);
	}
	
	public void clear() {
		mOverlays.clear();
		populate();
		setLastFocusedIndex(-1);
	}
}
